<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class PackageSetting extends Base
{
    use  SoftDeletes;
    static $one_price = '';

    protected $fillable = ['month', 'month_price', 'can_delete', 'admin_id'];

    public $appends = ['cheap_price_yuan', 'month_price_yuan', 'total_price_yuan'];

    private static function getOneMonthPrice() {
        if (self::$one_price)
            return self::$one_price;

        $self = new self();
        return self::$one_price = $self->where('month', 1)->value('month_price');
    }

    public function getCheapPriceYuanAttribute() {
        return format_yuan( $this->month * (self::getOneMonthPrice() - $this->month_price ) );
    }

    public function getMonthPriceYuanAttribute() {
        return format_yuan($this->month_price);
    }

    public function getTotalPriceYuanAttribute() {
        return format_yuan($this->month_price * $this->month);
    }



}
